package app.netant.book.xiaoshuo2016;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class XiaoShuo2016Detail extends BaseDetail {

	public XiaoShuo2016Detail(String netSite) {
		super(netSite);
		this.preHref = "https://www.xiaoshuo2016.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".content .contentCon .intro .introMid h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".content .contentCon .intro .introMid .phr p");
		if(parts.size()>0){
			String tags = parts.get(0).text();
			this.splitTagsPlus("：,:",tags, true);
		}
	}

	@Override
	public void analyseMemo() {
		
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".content .contentCon .intro .introMid .buttons a.sheetBn");
		if(parts.size()>0){
			
			for(int i=0;i<parts.size();i++){
				
				String txt = parts.get(i).text();
				
				if(txt.indexOf("下载")>=0){
					
					String url = parts.get(i).attr("href");
					if(url.startsWith("/")){
						url = this.preHref + url;
					}
					System.out.println("【Url】:"+url);
					
					XiaoShuo2016Detail detail = new XiaoShuo2016Detail(url);
					String href = detail.stepHref();
					System.out.println("【Href】:"+href);
					
					this.entity.setDownPath(href);
					
					break;
				}
				
			}

		}
	}
	
	public String stepHref(){
		Elements parts = this.select(".p_still section.detail article.de_con a");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			if(href.startsWith("/")){
				href = this.preHref + href;
			}
			return href;
		}
		return null;
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".content .contentCon .route a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		XiaoShuo2016Detail detail = new XiaoShuo2016Detail("https://www.xiaoshuo2016.com/282640/");
		detail.test();
	}



}
